package ru.compft.app.as_db.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import ru.compft.app.as_db.business.BusinessFacade;
import ru.compft.web.beans.ErrorBean;

import javax.annotation.Resource;
import java.io.Serializable;

/**
 * User: VVasiliev
 * Date: 14.06.12
 * Time: 13:43
 * Контроллер Главной страницы
 */
@Controller("mainController")
@RequestMapping("/main")
@Scope("session")
public class MainController implements Serializable {
    private static final long serialVersionUID = 4723551316168437774L;

    private static final Logger logger = LoggerFactory.getLogger(MainController.class);

    private static final String DEFAULT_VIEW = "main";

    @Resource(name = "errorBean")
    private ErrorBean errorBean;

    @Resource(name = "appBusinessDelegate")
    private BusinessFacade appBusinessDelegate;

    @ModelAttribute(ErrorBean.BEAN_NAME)
    public ErrorBean getErrorBean() {
        return errorBean;
    }

    /**
     * Отображение страницы по умолчанию
     *
     * @return
     */
    @RequestMapping(method = RequestMethod.GET)
    public String showDefaultPage() {
        System.out.println("Show default view");

        if (logger.isDebugEnabled()) {
            logger.debug("Show default view - " + DEFAULT_VIEW);
        }

        return DEFAULT_VIEW;
    }
}
